
/**
 * created on 2012-03-21
 * @author  qiujz
 * @version 1.0
 *
 * Copyright (c)  Founder Software (Suzhou) Co., Ltd.  2012
 *  All rights reserved.
 *
 * 
 * ================================================================
 * Change Revision
 * ---------------------------------------------------------------
 *    DATE                BY                   COMMENT
 * ---------------------------------------------------------------
 * 2012-03-21         qiujz                Create class
 * 
 *
 * ================================================================
 */
package com.founder.bm.controller
{
	import com.founder.bm.common.CommonUtils;
	import com.founder.bm.entity.EnrollInfQueryParameter;
	import com.founder.bm.entity.EnrollInfVo;
	import com.founder.bm.model.EnrollInfModel;
	import com.founder.framework.base.BaseController;
	import com.founder.framework.base.BaseEvent;
	import com.founder.framework.base.BaseModel;
	import com.founder.framework.interfaces.IControllerable;
	
	import mx.collections.ArrayCollection;
	import mx.core.FlexGlobals;
	import mx.rpc.AsyncResponder;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	/**
	 * 页面控制器对象
	 * @author qiujz
	 */
	public class EnrollInfController extends BaseController implements IControllerable
	{
		/**
		 * 构造函数
		 * @param model
		 */
		public function EnrollInfController(model:EnrollInfModel)
		{
			super(model);

			_service=new RemoteObject();
			_service.destination="bm.enrollInfService";
			_service.endpoint=CommonUtils.getServer(CommonUtils.BM);
			_service.showBusyCursor=true;
		}

		/**
		 * 获取页面模型对象
		 * @return 模型对象 
		 */
		public function get model():EnrollInfModel
		{
			return _model as EnrollInfModel;
		}

	
		/**
		 * 取得远程对象查询实体的方法
		 * @return 远程对象查询实体的接口方法
		 */
		public function get getEntityOperation():Object
		{
			return _service.getEnrollInfByPrimaryKey;
		}

		/**
		 * 取得远程对象检索实体的方法
		 * @return 远程对象检索实体的接口方法
		 */
		public function get searchOperation():Object
		{
			return _service.searchEnrollInfList;
		}

		/**
		 * 取得远程对象新增实体的方法
		 * @return 远程对象新增实体的接口方法
		 */
		public function get insertOperation():Object
		{
			return _service.insertEnrollInf;
		}

		/**
		 * 取得远程对象修改实体的方法
		 * @return 远程对象修改实体的接口方法
		 */
		public function get modifyOperation():Object
		{
			return _service.updateEnrollInf;
		}

		/**
		 * 取得远程对象删除实体的方法
		 * @return 远程对象删除实体的接口方法
		 */
		public function get deleteOperation():Object
		{
			return _service.deleteEnrollInf;
		}

		/**
		 * 取得远程对象批量删除实体的方法
		 * @return 远程对象批量删除实体的接口方法
		 */
		public function get deleteBatchOperation():Object
		{
			return _service.deleteEnrollInfBatch;
		}
		
		public function searchInfoDtl(userId:String):AsyncToken{
			var token:AsyncToken = _service.searchInfoDtl.send(userId);
			token.addResponder(new AsyncResponder(searchSuccessHandler, faultHandler, token));
			return token;
		}
		
		protected function searchSuccessHandler(event:ResultEvent, token:AsyncToken = null):void {
			var l:ArrayCollection = event.result.enrollInfoList as ArrayCollection;
			if(l != null && l.length > 0){
				EnrollInfModel(_model).enrollInf = l.getItemAt(0) as EnrollInfVo;
			}else{
				EnrollInfModel(_model).enrollInf = new EnrollInfVo();
			}
			EnrollInfModel(_model).enrollDtlList = event.result.enrollDtlList as ArrayCollection;
			this.doDispatchEvent(BaseEvent.SEARCH_SUCCESS);
		}
		
		public function saveInfDtl(enrollInfo:EnrollInfVo, enrollDtlList:ArrayCollection):AsyncToken{
			var token:AsyncToken = _service.saveInfDtl.send(enrollInfo, enrollDtlList);
			token.addResponder(new AsyncResponder(doMyInsertHandler, faultHandler, token));
			return token;
		}
		
		protected function doMyInsertHandler(event:ResultEvent, token:AsyncToken = null):void {
			successHandler();
			doDispatchEvent(BaseEvent.INSERT_SUCCESS);
		}
	}
}
